home *** CD-ROM | disk | FTP | other *** search
- Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
- From: thay@uoguelph.ca (Toby K Hay)
- Newsgroups: comp.lang.c
- Subject: Re: bubble sort walkthrough needed, please
- Date: 17 Apr 1996 20:56:02 GMT
- Organization: University of Guelph
- Message-ID: <4l3lt2$k3c@ccshst05.uoguelph.ca>
- References: <4l39b4$s2h@coranto.ucs.mun.ca>
- NNTP-Posting-Host: ccshst01.uoguelph.ca
- X-Newsreader: TIN [version 1.2 PL2]
-
- J.Deeley (jdeeley@calvin.stemnet.nf.ca) wrote:
- : I am trying to understand how this bubble sort is working. I understand
- : the theory, and I understand how the whole thing works except for the
- : few lines under the comment /* now sort them using a bubble sort */
- : In other words, it's only the lines
-
- : for(a=1; a<count; a++)
- : for(b=count-1; b>=a;--b)
-
- : that I can't fathom. I've been working at this ever since last night and
- : I still don't get it. Could someone tell me what is going on in that
- : part?
-
- Let a relative newcomer try. The first line says do the following with 'a'
- taking every value from 1 up to 'count-1'. Using 'a' to index the array
- 'item' will get you the values in the second position up to the position
- numbered' count'. The second line says do the following with 'b' taking
- every value from 'count-1' down to 'a'. Using 'b' to index the array
- 'item' will get you the values in the position numbered 'count' down to
- the position numbered 'a'. 'count-1' is used as a limit rather than
- 'count' because the array 'item' is numbered starting at 0 as are all
- arrays in C.
- Toby Hay thay@uoguelph.ca
-
-
-